//
//  JQFYSpecialDetailsTableViewCell.m
//  JQFY
//
//  Created by 代辉 on 2017/11/14.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYSpecialDetailsTableViewCell.h"

@interface JQFYSpecialDetailsTableViewCell ()

@property (nonatomic,weak) UIButton *numberButton;
@property (nonatomic,weak) UILabel *nameLabel;
@property (nonatomic,weak) UIButton *durationButton;

@end

@implementation JQFYSpecialDetailsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    UIButton *numberButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [numberButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [numberButton setBackgroundImage:[UIImage imageNamed:@"Pause"] forState:UIControlStateSelected];
    [numberButton setTitle:@"" forState:UIControlStateSelected];
    [self.contentView addSubview:numberButton];
    [numberButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(13 *SCAL);
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(9 *SCAL);
        make.height.mas_equalTo(14 *SCAL);
    }];
    
    UILabel *nameLabel = [UILabel new];
    nameLabel.textColor = [UIColor darkGrayColor];
    nameLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(numberButton.mas_right).offset(13 *SCAL);
        make.width.mas_equalTo(270 *SCAL);
    }];
    
    UIButton *durationButton = [UIButton new];
    [durationButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [durationButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [durationButton setTitle:@"00:00" forState:UIControlStateNormal];
    [durationButton setTitle:@"¥0.9" forState:UIControlStateSelected];
    [durationButton setBackgroundImage:[UIImage imageNamed:@"每首歌的价格"] forState:UIControlStateSelected];
    durationButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:durationButton];
    [durationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-20 *SCAL);
        make.width.mas_equalTo(50 *SCAL);
        make.height.mas_equalTo(30 *SCAL);
    }];
    
    UIImageView *hotImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"Rating%zd",arc4random_uniform((uint32_t)4)+1]]];
    [self.contentView addSubview:hotImgView];
    [hotImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(durationButton.mas_left).offset(-15 *SCAL);
    }];
    self.numberButton = numberButton;
    self.nameLabel = nameLabel;
    self.durationButton = durationButton;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];
   
    self.numberButton.selected = selected;
    self.durationButton.selected = selected;
}

- (void)setSongInfo:(JQFYSong *)songInfo
{
    _songInfo = songInfo;
    self.nameLabel.text = songInfo.music_name;
    
}

- (void)setIndexPath:(NSIndexPath *)indexPath
{
    _indexPath = indexPath;
    [self.numberButton setTitle:[NSString stringWithFormat:@"%zd",indexPath.row + 1] forState:UIControlStateNormal];
}
@end
